package com.snow.common.controller;

import com.snow.annotation.SysLog;
import com.snow.conditions.*;
import com.snow.jpa.model.BasePageParams;
import com.snow.common.entity.SystemLogEntity;
import com.snow.common.service.SystemLogService;
import com.snow.service.IAuthComponent;
import com.snow.view.PageData;
import com.snow.view.WebResponse;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/system-log")
public class SystemLogController {

    private final SystemLogService systemlogService;
    private final IAuthComponent authComponent;

    public SystemLogController(SystemLogService systemlogService, @Autowired(required = false) IAuthComponent authComponent) {
        this.systemlogService = systemlogService;
        this.authComponent = authComponent;
    }

    @Getter
    @Setter
    @QueryDescription(sort = {@Order(value = "createTime", type = QueryOrderType.desc)})
    public static class PageParams extends BasePageParams {
        @QueryConditionField
        private Integer createId;
        @QueryConditionField(type = ConditionType.like)
        private String createName;
    }

    @SysLog(value = "日志查询")
    @PostMapping("/page")
    public WebResponse<PageData<SystemLogEntity>> page(@RequestBody PageParams params) {
        if (authComponent != null && authComponent.getCurrentUser().isSystemAdmin()) {
            log.info("todo 此处考虑系统管理员，禁用租户限制");
        }
        return WebResponse.success(systemlogService.page(params));
    }


}
